<?php
function getHourInSeconds($unixtime)
{
	$hours = date('H',$unixtime);
	$difference = date('Z');
	$result = $hours*60*60 - ($difference);
	return $result;
}


$entity = get_entity(get_input('guid'));
$org = get_entity(get_input('org_guid'));

//Hours of the event (00:00, 00:30, 01:00, etc...)
$seconds = array();
for($i = 0-(date('Z')); $i < (30*48*60)-(date('Z')); $i = ($i + 30*60)) $minutes[$i] = date('H:i', $i);

//Tabs
$tabOptions = array(
	//Basic info
	array
	(
		'title' 	=> '1.- Informacion basica',
		'url' 		=> '#basic-info',
		'id' 		=> 'basic-info',
		'selected'	=> true
	),
	//Timetable info
	array
	(
		'title' 	=> '2.- Horarios',
		'url' 		=> '#timetable-info',
		'id' 		=> 'timetable-info',
		'selected'	=> false
	),
	//Prizes info
	array
	(
		'title' 	=> '3.- Premios',
		'url' 		=> '#prizes-info',
		'id' 		=> 'prizes-info',
		'selected'	=> false
	),
	//Categories info
	array
	(
		'title' 	=> '4.- Categorias',
		'url' 		=> '#categories-info',
		'id' 		=> 'categories-info',
		'selected'	=> false
	),
	//Documents info
	array
	(
		'title' 	=> '5.- Documentacion',
		'url' 		=> '#documents-info',
		'id' 		=> 'documents-info',
		'selected'	=> false
	),
	//Confirm save
	array
	(
		'title' 	=> '6.- Confirmar y Guardar',
		'url' 		=> '#confirm-save',
		'id' 		=> 'confirm-save',
		'selected'	=> false
	),
);

echo elgg_view('navigation/wizard_steps',array("tabs" => $tabOptions, "id" => 'save-section-tabs'));
?>

<script type="text/javascript">

</script>

<?php
//Guid of the tournament (when editing) or org_guid when adding 
echo elgg_view("input/hidden", array('name' => 'guid', "value" => get_input('guid')));
echo elgg_view("input/hidden", array('name' => 'org_guid', "value" => get_input('org_guid'))); 
?>

<style>
.form-section-body
{
	padding: 10px 0;
}
.elgg-module-featured > .elgg-head
{
	cursor: hand;
	cursor: pointer;
}
</style>

<!-- Basic info Section -->
<?php echo elgg_view('forms/tournaments/save_sections/basic_info', array('entity' => $entity, 'minutes' => $minutes));?>

<!-- Timetable -->
<?php echo elgg_view('forms/tournaments/save_sections/timetable', array('entity' => $entity, 'minutes' => $minutes));?>

<!-- Prizes -->
<?php echo elgg_view('forms/tournaments/save_sections/prizes', array('entity' => $entity));?>

<!-- Categories -->
<?php echo elgg_view('forms/tournaments/save_sections/categories', array('entity' => $entity));?>

<!-- Documents -->
<?php echo elgg_view('forms/tournaments/save_sections/documents', array('entity' => $entity));?>

<!-- Confirm save -->
<?php echo elgg_view('forms/tournaments/save_sections/confirm_save', array('entity' => $entity));?>


<script type="text/javascript">
//Sections
$('ul.elgg-wizard-steps').children().children().click(function(event)
{
	var id = $(this).attr('href');
	
	//Hide all sections & show the selected one
	$('.form-section-body').hide();
	$(id).fadeIn('slow');
	
	//Deselect all tabs and select the current one
	$('ul.elgg-wizard-steps > li > a').addClass('elgg-state-disabled');
	$('ul.elgg-wizard-steps > li > a').removeClass('elgg-button-special');
	
	$(this).removeClass('elgg-state-disabled');
	$(this).addClass('elgg-button-special');
	
	event.preventDefault();
});

// Help info boxes
$(".elgg-module-featured > .elgg-head").click(function()
{
	var body = $(this).next();
	if($(body).css('display') == 'none')
	{
		//$(body).css('display','block');
		$(body).slideDown('slow');
	}
	else
	{
		//$(body).css('display','none');
		$(body).slideUp('slow');
	}
});

//Next & Back buttons
$("div.buttons > a").click(function(event)
{
	var id = $(this).attr('href');
	$("li > a[href$="+id+"]").click();
	event.preventDefault();
});
</script>
